package com.CampaignManager.client;

import com.CampaignManager.shared.PlayerDTO;
import com.CampaignManager.shared.ResourceAmountDTO;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Widget;

public class ResourceForm extends Composite {

	private static ResourceFormUiBinder uiBinder = GWT
			.create(ResourceFormUiBinder.class);

	interface ResourceFormUiBinder extends UiBinder<Widget, ResourceForm> {
	}

	public ResourceForm() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@UiField
	FlexTable playerResourceTable;
	
	public void RefreshTable(PlayerDTO playerInfo) {
		
		playerResourceTable.removeAllRows();
		
		playerResourceTable.setText(0, 0, "Resource");
		playerResourceTable.setText(0, 1, "Amount");
		
		playerResourceTable.getRowFormatter().addStyleName(0, "watchListHeader");
		playerResourceTable.addStyleName("watchList");
		
		for (ResourceAmountDTO prc : playerInfo.getResources()) {
			int row = playerResourceTable.getRowCount();

			playerResourceTable.setText(row, 0, prc.getResource());
			playerResourceTable.setText(row, 1, prc.getAmount().toString());
		}		
	}
}
